function PCMSAD(PID) {
  this.ID        = PID;
  this.PosID  = 0; 
  this.ADID		  = 0;
  this.ADType	  = "";
  this.ADName	  = "";
  this.ADContent = "";
  this.PaddingLeft = 0;
  this.PaddingTop  = 0;
  this.Width = 0;
  this.Height = 0;
  this.IsHitCount = "N";
  this.UploadFilePath = "";
  this.URL = "";
  this.SiteID = 0;
  this.ShowAD  = showADContent;
  this.Stat = statAD;
}

function statAD(id) {
	var sp = document.createElement("SCRIPT");
	sp.type = "text/javascript";
	sp.src = "<?php echo Yii::app()->createAbsoluteUrl('api/adstat');?>/adzoneid/"+this.PosID+"/adseid/"+id;
	document.body.appendChild(sp);
}

function showADContent() {
  var content = this.ADContent;
  var isIE=!!window.ActiveXObject;
  var str = "<div id='PCMSAD_"+this.PosID+"'>";
  var AD = eval('('+content+')');
  var count = 0;
  if(AD.ADImage.length){
	  count = AD.ADImage.length;
  }
  for(var i=0;i<count;i++){
	if (isIE){

		if (document.readyState=="complete"){
			this.Stat(AD.ADImage[i].zds_id);
		} else {
			document.onreadystatechange=function(){
				if(document.readyState=="complete") this.Stat(AD.ADImage[i].zds_id);
			}
		}
	} else {
		this.Stat(AD.ADImage[i].zds_id);
	}
      //广告列表代码
      if (this.ADType == 1) {
          str += "<li onclick='statAD("+AD.ADImage[i].zds_id+");' style='list-style:none'><a href='"+this.URL+"/adseid/"+this.ADID+"/url/"+AD.ADImage[i].zds_url+"' target='_blank'>";
          str += "<img title='"+AD.ADImage[i].zds_title+"' src='"+AD.ADImage[i].zds_file_url+"' width='"+this.Width+"' height='"+this.Height+"' style='border:0px;'>";
          str += "</a></li>";
      }else if(this.ADType == 2){
          str += "<li style='list-style:none'><object onclick='alert(0);' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' width='"+this.Width+"' height='"+this.Height+"' id='FlashAD_"+this.ADID+"' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0'>";
          str += "<param name='movie' value='"+AD.ADImage[i].zds_file_url+"' />"; 
          str += "<param name='quality' value='autohigh' />";
          str += "<param name='wmode' value='opaque'/>";
          str += "<embed src='"+AD.ADImage[i].zds_file_url+"' quality='autohigh' wmode='opaque' name='flashad' swliveconnect='TRUE' pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash' type='application/x-shockwave-flash' width='"+this.Width+"' height='"+this.Height+"'></embed>";
          str += "</object><div style='position:absolute;z-index:10;width:"+this.Width+"px;height:"+this.Height+"px;'>123</div></li>";	  
      }
	}
  str += "</div>";
  document.write(str);
}

var cmsAD_<?php echo $adzone['zdz_id'];?> = new PCMSAD('cmsAD_<?php echo $adzone['zdz_id'];?>'); 
cmsAD_<?php echo $adzone['zdz_id'];?>.PosID = <?php echo $adzone['zdz_id'];?>; 
cmsAD_<?php echo $adzone['zdz_id'];?>.ADID = <?php echo $adzone['zdz_id'];?>; 
cmsAD_<?php echo $adzone['zdz_id'];?>.ADType = "<?php echo $adzone['zdz_type'];?>"; 
cmsAD_<?php echo $adzone['zdz_id'];?>.ADName = ""; 
cmsAD_<?php echo $adzone['zdz_id'];?>.ADContent = '{"ADImage":<?php echo json_encode($adzone['ads']);?>}'; 
cmsAD_<?php echo $adzone['zdz_id'];?>.URL = "<?php echo Yii::app()->createAbsoluteUrl('api/adclick');?>"; 
cmsAD_<?php echo $adzone['zdz_id'];?>.SiteID = ""; 
cmsAD_<?php echo $adzone['zdz_id'];?>.Width = <?php echo $adzone['zdz_width'];?>; 
cmsAD_<?php echo $adzone['zdz_id'];?>.Height = <?php echo $adzone['zdz_height'];?>; 
cmsAD_<?php echo $adzone['zdz_id'];?>.UploadFilePath = "<?php $params=Yii::app()->getParams();echo $params['uploadPath']?>"; 
cmsAD_<?php echo $adzone['zdz_id'];?>.ShowAD();
